from sqlalchemy import Column, Text, Integer, DATETIME

from .base_model import BaseModel


class Notice(BaseModel):
    __tablename__ = 'notice'
    __table_args__ = {'extend_existing': True}
    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
    content = Column(Text, nullable=False, comment="公告内容")
    status = Column(Integer, nullable=False, default=0, comment="公告状态")
    publish_time = Column(DATETIME, comment="更新时间")

    def __repr__(self):
        return f"<Notice(id={self.id}, content={self.content}, status={self.status})>"

    def to_dict(self):
        return {
            "id": self.id,
            "content": self.content,
            "status": self.status,
            "publish_time": self.publish_time.strftime('%Y-%m-%d %H:%M:%S') if self.publish_time else None  # 格式化日期时间
        }

    class Config:
        orm_mode = True
